/*
 * AirPlane.cpp
 *
 *  Created on: 2012/07/08
 *      Author: weihe
 */

#include "AirPlane.h"

namespace object {

const float AirPlane::BASE_SPEED = 25;

AirPlane::~AirPlane()
{
}

void AirPlane::aileron(float rad)
{
	_aileron = rad;
}

void AirPlane::elevator(float rad)
{
	_elevator = rad;
}
//static const float RAD = 180.0 / M_PI;
void AirPlane::update(float dt)
{

	float pitch = camera->pitch();
	float bank = camera->bank();
	speed = calcSpeed();
	dt /= 2;
	//camera->yaw(_rudder / 2 * dt);
	camera->rotHeading(_rudder * dt);
	camera->pitch((_elevator - pitch) * dt);
	camera->roll((_aileron - bank) * dt);
	camera->shiftFront(speed * dt);
//	printf(
//			"Heading: %.1f Pitch: %.1f Bank: %.1f Speed: %.1f (%.1f, %.1f, %.1f)\n",
//			camera->heading() * RAD, camera->pitch() * RAD,
//			camera->bank() * RAD, speed, camera->position.x, camera->position.y,
//			camera->position.y);
}

void AirPlane::rudder(float rad)
{
	_rudder = rad;
}

float AirPlane::calcSpeed()
{
	return BASE_SPEED * (1 - camera->pitch() / 2);
}

} /* namespace object */
